//---------------------------------------------------------------------------
function UserList(idMembers, idAvailables)
{
	this.move = function(idSrc, idDst)
	{
		var i;
		var s = $(idSrc), d = $(idDst);
		for (i = s.options.length - 1; i >= 0; i--)
			if (s.options[i].selected) {
				s.options[i].selected = false;
				d.options[d.options.length] = new Option(s.options[i].text, s.options[i].value);
				s.options[i] = null;
			}
	}

	this.join = function()
	{
		this.move(this.a, this.m);
	}

	this.part = function()
	{
		this.move(this.m, this.a);
	}

	this.m = idMembers;
	this.a = idAvailables;

	return this;
}
//---------------------------------------------------------------------------
function MemberList(id)
{
	this.handler = $(id);

	this.choose = function(value)
	{
		var list = this.handler;
		for (var i = 0; i < list.options.length; i++)
			if (list.options[i].value == value) {
				list.selectedIndex = i;
				return;
			}
	}

	this.select = function(value)
	{
		var list = this.handler;
		for (var i = 0; i < list.options.length; i++)
			if (list.options[i].value == value) {
				list.options[i].selected = true;
				return;
			}
	}

	this.selectAll = function()
	{
		var list = this.handler;
		for (var i = 0; i < list.options.length; i++)
			list.options[i].selected = true;
	}

	return this;
}

function doCompleteProject(project_id, completed_date, forceComplete) {
	if (completed_date == '') {
		alert('Please input completed date!');
		return;
	}
	if (forceComplete == 0) {
		go("index.php?m=projects&a=do_project_complete&project_id=" + project_id + "&completed_date=" + completed_date);
	} else {
		go("index.php?m=projects&a=do_project_force_complete&project_id=" + project_id + "&completed_date=" + completed_date);
	}
}

function closeDialog(id){
    Control(id).destroy();
	Dialog(id).hide();
}

function confirmForceComplete(project_id) {
	if (!confirm('Do you want to force complete this reference')) {
		return false;
	}
	go("index.php?m=projects&a=do_project_force_complete&project_id=" + project_id);
}

function goNewTask(project_id) {
	go("?m=tasks&a=simpleaddedit&task_project=" + project_id);
}

function goNewTaskLog(project_id) {
	go("?m=timecard&tab=1&task_project=" + project_id);
}

function openSalesAmountDialog(task_id, value, task_name){
	Dialog('idSalesAmountDialog', 1000).show();
	$('saTaskId').value = task_id;
	if (typeof(value) != 'undifined' && value != null) {
		$('idSalesAmountInput').value = value;
	}
	if (typeof(task_name) != 'undifined' && task_name != null) {
		$('saTaskName').innerHTML = task_name;
	}
	setTimeout('$("idSalesAmountInput").focus()', 100);
	return false;
}

function closeSalesAmountDialog(id){
    Control(id).destroy();
	Dialog(id).hide();
}
//---------------------------------------------------------------------------
